package com.metaboot.demo.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.metaboot.common.annotation.Log;
import com.metaboot.common.core.controller.BaseController;
import com.metaboot.common.core.domain.AjaxResult;
import com.metaboot.common.enums.BusinessType;
import com.metaboot.demo.domain.DemoTree;
import com.metaboot.demo.service.IDemoTreeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.metaboot.common.utils.poi.ExcelUtil;

/**
 * 树表演示Controller
 * 
 * @author theodo
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/demo/tree")
@Api(value = "树表演示控制器", tags = {"树表演示"})
public class DemoTreeController extends BaseController {
    @Autowired
    private IDemoTreeService demoTreeService;

    /**
     * 查询树表演示列表
     */
    @ApiOperation("查询树表演示列表")
    @PreAuthorize("@ss.hasPermi('demo:tree:list')")
    @GetMapping("/list")
    public AjaxResult list(DemoTree demoTree) {
        List<DemoTree> list = demoTreeService.selectDemoTreeList(demoTree);
        return AjaxResult.success(list);
    }

    /**
     * 导出树表演示列表
     */
    @ApiOperation("导出树表演示列表")
    @PreAuthorize("@ss.hasPermi('demo:tree:export')")
    @Log(title = "树表演示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DemoTree demoTree) {
        List<DemoTree> list = demoTreeService.selectDemoTreeList(demoTree);
        ExcelUtil<DemoTree> util = new ExcelUtil<DemoTree>(DemoTree.class);
        util.exportExcel(response, list, "树表演示数据");
    }

    /**
     * 获取树表演示详细信息
     */
    @ApiOperation("获取树表演示详细信息")
    @PreAuthorize("@ss.hasPermi('demo:tree:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(demoTreeService.selectDemoTreeById(id));
    }

    /**
     * 新增树表演示
     */
    @ApiOperation("新增树表演示")
    @PreAuthorize("@ss.hasPermi('demo:tree:add')")
    @Log(title = "树表演示", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DemoTree demoTree) {
        return toAjax(demoTreeService.insertDemoTree(demoTree));
    }

    /**
     * 修改树表演示
     */
    @ApiOperation("修改树表演示")
    @PreAuthorize("@ss.hasPermi('demo:tree:edit')")
    @Log(title = "树表演示", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DemoTree demoTree) {
        return toAjax(demoTreeService.updateDemoTree(demoTree));
    }

    /**
     * 删除树表演示
     */
    @ApiOperation("删除树表演示")
    @PreAuthorize("@ss.hasPermi('demo:tree:remove')")
    @Log(title = "树表演示", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(demoTreeService.deleteDemoTreeByIds(Arrays.asList(ids)));
    }
}
